package com.mayuanfei.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * TODO 类描述
 *
 * @author 老马
 * @date 2023-03-23 13:09
 */
@Controller
@RequestMapping("test")
public class MyController2 {

    @RequestMapping(value = {"hello", "hello2.json"})
    public String hello() {
        System.out.println("hello world");
        return "first";
    }

    @RequestMapping(value = "hello2", method = RequestMethod.GET)
    public String hello2() {
        System.out.println("hello world2");
        return "first";
    }

    @RequestMapping(value = "hello3", params = {"username","password!=123456"})
    public String hello3() {
        System.out.println("hello world3");
        return "first";
    }

    @RequestMapping(value = "hello4", headers = "token")
    public String hello4() {
        System.out.println("hello world4");
        return "first";
    }

    @RequestMapping(value = "hello5", consumes = "application/json")
    public String hello5() {
        System.out.println("hello world5");
        return "first";
    }


    @RequestMapping(value = "hello6", produces = "application/json")
    @ResponseBody
    public String hello6(HttpServletResponse response) throws IOException {
        String retJson = "{\"username\":\"laoma\",\"userid\":123456}";
        System.out.println("hello world6");
        return retJson;
    }
}